
var logo = ""; var conamevlue = "";
$(window).resize(function () {
    console.log(123);
    $("#table_list_1").setGridHeight($(window).height() - 300);
    $("#table_list_1").setGridWidth($(window).width());


});
var sbtype = "0";
function add() {
    var AZ = ["co_name", "contact", "address", "telephone", "status", "remarks", "superiorcompanyid", "logo", "Lgsv_server_id",
        "File_server_id", "is_GPS", "is_regional", "is_push", "push_url", "push_account", "push_password", "type", "high", "width", "is_group"];
    //字段 

    var val = [$("#co_name").val(), $("#contact").val(), $("#address").val(), $("#telephone").val(), $("#status").val(), $("#explain").val(), $("#company_id").val() == "" ? "0" : $("#company_id").val(), logo, $("#Lgsv_server_id").val(), $("#File_server_id").val(), $("#is_GPS").val(), $("#is_regional").val(), $("#is_push").val(), $("#push_url").val(), $("#push_account").val(), $("#push_password").val(), sbtype, $("#high").val(), $("#width").val(), $("#is_group").val()];


    var findval = {
        "sessionid": sessionStorage.getItem("sid"), "co_name": $("#co_name").val(), "contact": $("#contact").val(), "address": $("#address").val(), "telephone": $("#telephone").val(),
        "status": $("#status").val(), "remarks": $("#explain").val(), "superiorcompanyid": $("#company_id").val(), "logo": logo, "Lgsv_server_id": $("#Lgsv_server_id").val(), "File_server_id": $("#File_server_id").val(), "is_GPS": $("#is_GPS").val(), "is_regional": $("#is_regional").val(), "is_push": $("#is_push").val(), "push_url": $("#push_url").val(), "push_account": $("#push_account").val(), "push_password": $("#push_password").val()
        , "type": sbtype, "high": $("#high").val(), "width": $("#width").val(), "is_group": $("#is_group").val(), "userid": sessionStorage.getItem("userId"), "username": sessionStorage.getItem("username")
    }

    // var
    //alert(conamevlue);
    if ($("#myModalLabel").text() == domain.language.$t('xinzeng')) {
        // alert($("#company_id").val());
        // var findval=domain.fieldthis(AZ,val,"company");

        //var json=
        // {"tableName":"userinfo", "fielded":""，” valueid”:”修改条件”,”fieldnameA”:”需要修改的字段”，”stringvalueA”:”修改值” }

        $("#sbtype").attr("disabled", "disabled");
        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/basicmManagementpage/queryCoNameByCoName?sessionid=" + sessionStorage.getItem("sid"),
            data: { "coname": $("#co_name").val(), "coid": $("#company_id").val() },
            success: function (response) {
                response = JSON.parse(response);
                if (response.code == "201") {

                    $("#myModal").find("span").eq(0).text(domain.language.$t('com_mcycz'));
                    // $("#user_name").focus();
                    return;
                } else {
                    //   add();


                    $.ajax({
                        type: 'POST',
                        url: domain.testUrl + "/Threeinjection/basicmManagementpage/insertCompany",
                        //url:domain.testUrl+"/Threeinjection/global/insert",
                        data: findval,
                        success: function (response) {
                            // console.log(response);
                            response = JSON.parse(response);
                            if (response.code == "200") {
                                parent.MenuTree(1);
                                $(".close").click();
                                pageval = 1;
                                cxlist();
                                swal(domain.language.$t('dev_success'), domain.language.$t('baocuncg'), "success");
                                $(".confirm").text(domain.language.$t('queding'));
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {

                            swal(domain.language.$t('dev_omg'), domain.language.$t('baocunsb'), "error");
                            $(".confirm").text(domain.language.$t('queding'));
                        }
                    });
                }
            }
        });

    } else {
        findval = domain.fieldupdatethis(AZ, val, "co_id", $("#co_id").val(), "company");
        if (conamevlue != $("#co_name").val()) {



            $.ajax({
                type: 'POST',
                url: domain.testUrl + "/Threeinjection/basicmManagementpage/queryCoNameByCoName?sessionid=" + sessionStorage.getItem("sid"),
                data: { "coname": $("#co_name").val(), "coid": $("#company_id").val() },
                success: function (response) {
                    response = JSON.parse(response);
                    if (response.code == "201") {

                        $("#myModal").find("span").eq(0).text( domain.language.$t('com_mcycz'));
                        return;
                    } else {

                        $.ajax({
                            type: 'POST',
                            url: domain.testUrl + "/Threeinjection/global/update",
                            data: findval,
                            success: function (response) {
                                // console.log(response);
                                response = JSON.parse(response);
                                if (response.code == "200") {
                                    pageval = 1;
                                    cxlist(); conameval = "";
                                    $(".close").click();
                                    swal(domain.language.$t('dev_success'),domain.language.$t('xiugaicg'), "success");
                                    $(".confirm").text(domain.language.$t('queding'));
                                }
                            }
                        });
                    }
                }
            });
        } else {
            $.ajax({
                type: 'POST',
                url: domain.testUrl + "/Threeinjection/global/update",
                data: findval,
                success: function (response) {
                    // console.log(response);
                    response = JSON.parse(response);
                    if (response.code == "200") {
                        pageval = 1;
                        cxlist(); conameval = "";
                        $(".close").click();
                        swal(domain.language.$t('dev_success'),domain.language.$t('xiugaicg'), "success");
                        $(".confirm").text(domain.language.$t('queding'));
                    }
                }
            });

        }
    }
}
$(function () {
    $(".confirm").text(domain.language.$t('queding'));
    logo = sessionStorage.getItem("logo");
    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/basicmManagementpage/queryServerInfo",
        data: { sessionid: sessionStorage.getItem("sid") },
        // datatype:"JSON",
        success: function (response) {
            // console.log(response);
            $.each(JSON.parse(response).LgsvServerInfo, function (i, item) {

                if (item.serverType == "1") {
                    var json = "<option value='" + item.id + "'>" + item.ipaddr + "---" + item.ipName + "</option>";

                    $("#Lgsv_server_id").append(json);

                }
                if (item.serverType == "2") {

                    var json = "<option value='" + item.id + "'>" + item.ipaddr + "---" + item.ipName + "</option>";

                    $("#File_server_id").append(json);
                }
                //console.log(item.roleName);

            });
            //  that.ret=data.ret;
            //that.options=JSON.parse(lgvsRole).lgvsRole;
        }
    });

    

    //单位隐藏宽高
    $("#is_group").change(function () {
        var contact = $("#highdiv").next();
        //单位
        if ($(this).val() == "0") {
            $("#widthdiv,#highdiv,#sbtypediv").hide()
            //联系人、电话必填标志
            contact.find("sqan").show();
            contact.next().find("sqan").show();

        } else {
            $("#widthdiv,#highdiv,#sbtypediv").show();
            contact.find("sqan").hide();
            contact.next().find("sqan").hide();
        }
    });

    $("#addt").click(function (z) {
        if ($("#sbtype").val() == "0" || $("#sbtype").val() == "1") {
            $("#Lgsv_server_id").val("2");
        } else {
            $("#Lgsv_server_id").val("1");
        }

        $("#myModal").find("span").empty();
        $("#myModal").find("input").val("");
        $("#myModalLabel").text(domain.language.$t('xinzeng'));
        $("#myModal").find(".form-group").eq(2).show();

        $('#sbtype').removeAttr("disabled");
        var contact = $("#highdiv").next();
        //卡组下不能建单位
        if (sessionStorage.getItem("isgroup") == "0") {
            $("#is_group").removeAttr("disabled");
            $("#widthdiv,#highdiv,#sbtypediv").hide()
            //联系人、电话必填标志
            contact.find("sqan").show();
            contact.next().find("sqan").show();
    
        } else {
            $("#is_group").val(1);
            $("#is_group").attr("disabled", true);
            $("#widthdiv,#highdiv,#sbtypediv").show();
            contact.find("sqan").hide();
            contact.next().find("sqan").hide();
        }
    });
    $("button").eq(0).click(function () {
        coidval = "";
        cxlist();
    });
    cxlist();
    $("#citySel").click(function () {
        var cityObj = $("#citySel");
        var cityOffset = $("#citySel").offset();
        //   alert(cityOffset.left-350);
        $("#menuContentmk").show();
        //   $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    });
    $("#company_name").click(function () {
        //  $("#co_id").val();
        //$("#co_id").val();
        $("#treeDemocompanytow").width(410);
        var cityObj = $("#company_name");
        var cityOffset = $("#company_name").offset();
        //  $("#menuContenttow").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
        $("#menuContenttow").show();
        $("body").bind("mousedown", onBodyDowntow);
    });
    $("#logoimg").click(function () {
        $('#logo').val("");
        $("#logo").click();

    });
    $('#logo').change(function () {
        handleFileSelect(this);

    });
  
        $("#co_name").blur(function(){
            $("#myModal").find("span").eq(0).text("");
           
        });
        

    $("#add").click(function () {
        $("#myModal").find("span").empty();
        if ($("#co_name").val().length == 0) {

            $("#myModal").find("span").eq(0).text(domain.language.$t('com_mcbnwk'));
            return;
        }
        //if($("#co_name").val().length>0 && $("#co_name").val().length<6){
        //   $("#myModal").find("span").eq(0).text("长度只能在6-20个字符之间");
        //  $("#user_name").focus();  
        //  return;
        //}
        //alert($("#myModal").find(".form-group").eq(2).css('display'));
        // alert($("#myModal").find(".form-group").eq(2).is(':hidden'));
        if ($("#myModal").find(".form-group").eq(2).css('display') == "block") {

            if ($("#company_name").val().length == 0) {
                swal(domain.language.$t('tishi'),domain.language.$t('sjmcbnwk'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
            

        }
        if ($("#is_group").val() == "1") {
            sbtype = $("#sbtype").val();

            if ($("#width").val() == "") {
                swal(domain.language.$t('tishi'),domain.language.$t('qsrpk'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            } if ($("#high").val() == "") {
                swal(domain.language.$t('tishi'),domain.language.$t('qsrpg'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
            if (parseInt($("#width").val()) < 16) {
                swal(domain.language.$t('tishi'),domain.language.$t('pkbxy16'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
            if (parseInt($("#high").val()) < 16) {
                swal(domain.language.$t('tishi'),domain.language.$t('pgbxy16'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
        } else {
            $("#high").val(0);
            $("#width").val(0);
            if ($("#contact").val() == "") {
                swal(domain.language.$t('tishi'),domain.language.$t('qsrlxr'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            } if ($("#telephone").val() == "") {
                swal(domain.language.$t('tishi'), domain.language.$t('qsrlxdh'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
        }
        if ($("#telephone").val() != "") {
            var isPhone = /^1[3456789]\d{9}$/;
            // var isMob = /^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;

            if (!isPhone.test($("#telephone").val())) {
                swal(domain.language.$t('tishi'),domain.language.$t('srdianhuacw'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return;
            }
        }
        // if ($("#Lgsv_server_id").val() == "") {

        //     swal(domain.language.$t('tishi'),domain.language.$t('com_qxzswID'), "error");
        //     return;
        // }
        // if ($("#File_server_id").val() == "") {

        //     swal(domain.language.$t('tishi'),domain.language.$t('com_qxzwjID'), "error");
        //     return;
        // }

        add();

    });

});

// if($("#citySel").val().length==0){

// $("#myModal").find("span").eq(3).text( domain.language.$t('com_qxzgnmk'));
//  return;
// }


if (window.File && window.FileReader && window.FileList && window.Blob) {
    //Blob是计算机界通用术语之一，全称写作：BLOB (binary large object)，表示二进制大对象。
    //全部支持
    window.handleFileSelect = function (target) {
        //console.log("fileadd");
        try {
            logo = "";
            var logoimg = document.getElementById("logoimg");
            logoimg.src = "./static/img/upload.jpg";

            var files = target.files, f = files[0];
            if (!/image\/\w+/.test(f.type)) {
                swal("",domain.language.$t('qqbwjwtxlx'), "error");
                $(".confirm").text(domain.language.$t('queding'));
                return false;
            }

            var zt = fileChangelog(document.getElementById("logo"));

            if (zt) {

                var reader = new FileReader();
                reader.onload = (function (theFile) {
                    return function (e) {

                        var logoimg = document.getElementById("logoimg");

                        logoimg.src = e.target.result;
                    };
                })(f);
                reader.readAsDataURL(f);
                var formData = new FormData();

                formData.append('file', $('#logo')[0].files[0]);
                $.ajax({
                    url: domain.testUrl + "/Threeinjection/basicmManagementpage/logoFileUpload?sessionid=" + sessionStorage.getItem("sid"),
                    type: 'POST',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    logo = res;
                    //res=logo;


                }).fail(function (res) {



                });


            }
        } catch (ex) {


        }
    }
    //	 document.getElementById('logo').addEventListener('change', handleFileSelect, false);
}
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
function fileChangelog(target) {
    var fileSize = 0;
    if (isIE && !target.files) {
        var filePath = target.value;
        var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
        var file = fileSystem.GetFile(filePath);
        fileSize = file.Size;

    } else {
        fileSize = target.files[0].size;

    }
    var size = fileSize / 1024;
    // alert(size);
    if (size > 5120) {
        // $("#logoimgtext").text("图片不能大于2M,请重新选择！");
        swal("", domain.language.$t('tupianbndy5'), "error");
        $(".confirm").text(domain.language.$t('queding'));
        return false;
    }
    return true;
}


$(document).ready(function () {
    $.jgrid.defaults.styleUI = "Bootstrap";
    $("#table_list_1").jqGrid({
        data: [],
        datatype: "local",
        height: "100%",
        recordtext: "{0} - {1}\u3000"+domain.language.$t('dev_gong')+" {2} "+domain.language.$t('dev_tiao'),
        pgtext : "{0} "+domain.language.$t('dev_gong')+" {1} "+domain.language.$t('dev_ye'),  
        emptyrecords: domain.language.$t('dev_wsjxs'),
        shrinkToFit: true,
        autoScroll: true,
        rowNum: 20,
        rowList: [10, 20, 30, 60, 90, 100, 200, 500],
        //colNames: ["编号", "名称", "手机号码"],
        colModel: [{
            name: 'co_id', index: 'co_id', align: "center", width: 10, label:domain.language.$t('dev_bianhao'), align: 'center',


        },


        {
            name: 'co_name', index: 'co_name', align: "center", width: 25, label: domain.language.$t('dev_mingcheng'), align: 'center',


        },


        {
            name: 'logo', index: 'logo', align: "center", width: 15, label: "Logo", align: 'center',
            formatter: function (value, options, row) {

                if (value != "") {

                    return "<img src='" + domain.testUrl + "/" + value + "' alt='' class='img-thumbnail' style='width:40px;height:40px;'>";

                } else {


                    return "<img src='static/img/暂无图片.png' alt='' class='img-thumbnail' style='width:40px;height:40px;'>";

                }

            }

        },

        {
            hidden: true, name: 'pname', index: 'pname', align: "center", width: 25, label: domain.language.$t('com_sjgs'), align: 'center',
        },
        {
            name: 'contact', index: 'contact', align: "center", width: 15, label: domain.language.$t('com_lianxiren'), align: 'center',
        },
        {
            name: 'telephone', index: 'telephone', align: "center", width: 20, label:domain.language.$t('com_dianhua'), align: 'center',


        },

        {
            name: 'address', index: 'address', align: "center", width: 30, label: domain.language.$t('com_dizhi'), align: 'center',


        },

        // {
        //     name: 'coName', index: 'coName',align:"center", width: 25, label:domain.language.$t('com_gnmk'), align: 'center',
        // }, 

        {
            name: 'Lgsv_server_name', index: 'Lgsv_server_name', align: "center", width: 30, label: domain.language.$t('com_swfwq'), align: 'center',
            hidden: true,

        },
        {
            name: 'File_server_name', File_server_name: 'File_server_name', align: "center", width: 30, label: domain.language.$t('com_wjfwq'), align: 'center',
            hidden: true,

        },

        {
            name: 'is_GPS', index: 'is_GPS', align: "center", width: 18, label:domain.language.$t('com_GPSgn'), align: 'center',
            hidden: false, formatter: function (value, options, row) {

                if (value == "1") {

                    return domain.language.$t('com_shi');
                } else {

                    return domain.language.$t('com_fou');

                }


            }

        },


        {
            name: 'is_regional', index: 'is_regional', align: "center", width: 18, label: domain.language.$t('com_quyugl'), align: 'center',
            hidden: false, formatter: function (value, options, row) {

                if (value == "1") {

                    return domain.language.$t('com_shi');
                } else {

                    return domain.language.$t('com_fou');

                }


            }

        },

        {
            name: 'is_push', index: 'is_push', align: "center", width: 30, label:domain.language.$t('com_tuisong'), align: 'center',
            hidden: true, formatter: function (value, options, row) {

                if (value == "1") {

                    return domain.language.$t('com_shi');
                } else {

                    return domain.language.$t('com_fou');

                }

            }

        },
        {
            hidden: true, name: 'push _url', index: 'push _url', align: "center", width: 30, label: domain.language.$t('com_jiekoudz'), align: 'center',


        },
        {
            hidden: true, name: 'push_account', index: 'push_account', align: "center", width: 30, label: domain.language.$t('yonghuming'), align: 'center',


        },
        {
            name: 'remarks', index: 'remarks', align: "center", width: 30, label: domain.language.$t('dev_shuoming'), align: 'center',


        },
        {
            name: 'Starttime', index: 'Starttime', align: "center", width: 30, label: domain.language.$t('com_shijian'), align: 'center',
            formatter: function (value, options, row) {

                if (typeof (value) != "undefined") {
                    try {
                        var date = new Date(value)

                        return date.Format("yyyy-MM-dd hh:mm:ss");
                    } catch (ex) {

                        console.log(ex);
                    }
                }
                return "";
            }

        },
        {
            name: '', index: '', width: 25, align: "center", label:domain.language.$t('dev_caozuo'), align: 'center',
            formatter: function (value, options, row) {

                //console.log(options.rowId);
                var html = "<button type='button'  class='btn btn-primary' onclick=modify('" + options.rowId + "');>"+domain.language.$t('xiugai')+"</button>";
                if (sessionStorage.getItem("coid") != row.co_id && sessionStorage.getItem("isgroup") != "1") {

                    html += "<button type='button'  class='btn btn-danger' onclick=del('" + row.co_id + "');>"+domain.language.$t('shanchu')+"</button>";
                } else {

                    if (sessionStorage.getItem("isgroup") == "1") {
                        html += "<button type='button'  class='btn btn-danger' onclick=del('" + row.co_id + "');>"+domain.language.$t('shanchu')+"</button>";

                    }

                }


                return html;
            }

        },


        ],
        pager: "#pager_list_1",
        viewrecords: true,
        caption: domain.language.$t('com_danweilb'),
        hidegrid: false,

        ondblClickRow: function (row) {


            $("#update").click();
            modify(row);
            // $('#myModal').modal('show')

        },
        onPaging: function (pageBtn) {
            console.log(":" + pageBtn);
            //	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数
            var re_page = $("#table_list_1").getGridParam('page');//获取返回的当前页
            var re_rowNum = $("#table_list_1").getGridParam('rowNum');//获取每页数
            var re_total = $("#table_list_1").getGridParam('lastpage');//获取总页数
            //alert(re_total);

            if (pageBtn === "next") {
                // initJqgrid(re_page+1,re_rowNum);
                // if()
                pageval = pageval + 1;
                cxlist();
            }
            if (pageBtn === "prev") {

                pageval = pageval - 1; cxlist();
            }

            if (pageBtn == "last") {

                pageval = re_total;

                cxlist();

            }
            if (pageBtn == "first") {

                pageval = 1;

                cxlist();

            }

            if (pageBtn == "records") {

                sizeval = $(".ui-pg-selbox").val();
                pageval = 1;
                cxlist();
            }
        },

    });
    $(".ui-pg-selbox").css("width", "50px");
});


window.sizeval = 20;
window.pageval = 1; window.coidval = "";
window.conameval = $("#usnameval").val();
var json = "";



window.cxlist = function () {

    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl + "/Threeinjection/basicmManagementpage/queryCompanyPage",
        data: { size: sizeval, page: pageval, coid: sessionStorage.getItem("coid"), coname: $("#usnameval").val(), sessionid: sessionStorage.getItem("sid") },
        // datatype:"JSON",
        success: function (response) {
            console.log(response);
            json = response;
            var data = JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },
            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');

            var re_records = $("#table_list_1").getGridParam('records');

            if (re_records == 0 || re_records == null) {
                if ($(".norecords").html() == null) {
                    $("#table_list_1").parent().append("<div class=\"norecords\">"+domain.language.$t('dev_meiyoufhsj')+"</div>");
                }
                $(".norecords").show();
            } else {

                $(".norecords").hide();
            }

            //  alert(ss.WinH);
            $("#table_list_1").setGridHeight($(window).height() - 300);
            //   $("#table_list_1").setGridHeight(ss.WinH-300);
            // $("#table_list_1").setGridWidth($(".col-md-10").width()-2);
            $("#table_list_1").setGridWidth($(window).width() - 10);

            //  $("#table_list_1").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'auto' });
        }


    });
}

window.del = function (id) {
    ///basicmManagementpage/deleteCompanyInfo  传入参数coid ，如果有多个参数以逗号分割。
    
    swal({
        title: domain.language.$t('tishi'),
        text: domain.language.$t('com_sfscdw'),
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: domain.language.$t('queding'),
        cancelButtonText: domain.language.$t('quxiao'),
        closeOnConfirm: false,
        closeOnCancel: true
    }, function ss(inputValue) {
        if (inputValue) {
        $.ajax({
            type: 'POST',
            url: domain.testUrl + "/Threeinjection/basicmManagementpage/deleteCompanyInfo",
            data: { "coid": id, sessionid: sessionStorage.getItem("sid") },
            success: function (response) {
                response = JSON.parse(response);
                if (response.code == "200") {
                    pageval = 1;
                    parent.MenuTree(1);
                    cxlist();
                    swal(domain.language.$t('dev_success'),domain.language.$t('scchenggong'), "success");
                    $(".confirm").text(domain.language.$t('queding'));
                } else {
                    swal(domain.language.$t('dev_omg'), domain.language.$t('scshibai'), "error");
                    $(".confirm").text(domain.language.$t('queding'));
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                swal(domain.language.$t('dev_omg'),  domain.language.$t('scshibai'), "error");
                $(".confirm").text(domain.language.$t('queding'));
            }
        });
    }
});
}
window.modify = function (i) {
    $("#myModal").find("span").empty();
    $("#myModalLabel").text( domain.language.$t('xiugai'));
    setTimeout(function () {
        $("#update").click();
    }, 500);
    i = i - 1;
    var jsonval = JSON.parse(json);
    $("#is_group").val(jsonval.rows[i].is_group);
    var contact = $("#highdiv").next();
    if (jsonval.rows[i].is_group == "1") {
        $("#sbtypediv,#highdiv,#widthdiv").show();
        $("#sbtype").val(jsonval.rows[i].type);
        $("#high").val(jsonval.rows[i].high);
        $("#width").val(jsonval.rows[i].width);
        contact.find("sqan").hide();
        contact.next().find("sqan").hide();
        $("#is_group").attr("disabled", true);

    } else {
        $("#sbtypediv,#highdiv,#widthdiv").hide();
        $("#sbtype").val(jsonval.rows[i].type);
        $("#high").val("");
        $("#width").val("");
        contact.find("sqan").show();
        contact.next().find("sqan").show();
       
    }

    
    // $("#user_name").val(json[i].email);
    $("#co_id").val(jsonval.rows[i].co_id);
    $("#co_name").val(jsonval.rows[i].co_name);
    conamevlue = jsonval.rows[i].co_name;
    $("#contact").val(jsonval.rows[i].contact);


    $("#sbtype").attr("disabled", "disabled");
    //sbtype

    if (jsonval.rows[i].logo != "" && typeof (jsonval.rows[i].logo) != "undefined") {

        logo = jsonval.rows[i].logo;
        $("#logoimg").attr("src", domain.testUrl + "/" + jsonval.rows[i].logo);
    }

    $("#logoimg").val(jsonval.rows[i].logo);

    $("#company_name").val(jsonval.rows[i].pname);
    $("#company_id").val(jsonval.rows[i].superiorcompanyid);

    if (typeof (jsonval.rows[i].pname) != "undefined") {
        $("#myModal").find(".form-group").eq(2).show();
        $("#myModal").find(".form-group").eq(1).hide();
        logo = sessionStorage.getItem("logo");
    } else {

        $("#myModal").find(".form-group").eq(1).show();
        $("#myModal").find(".form-group").eq(2).hide();
    }
    $("#telephone").val(jsonval.rows[i].telephone);
    $("#address").val(jsonval.rows[i].address);


    if (jsonval.rows[i].Lgsv_server_id != "0" && typeof (jsonval.rows[i].Lgsv_server_id) != "undefined") {
        $("#Lgsv_server_id").val(jsonval.rows[i].Lgsv_server_id);
    }
    //this.console.log(jsonval.rows[i].File_server_id);
    if (jsonval.rows[i].File_server_id != "0" && typeof (jsonval.rows[i].File_server_id) != "undefined") {
        //alert(jsonval.rows[i].companyId);
        $("#File_server_id").val(jsonval.rows[i].File_server_id);
    }
    if (jsonval.rows[i].is_GPS != "0" && typeof (jsonval.rows[i].is_GPS) != "undefined") {

        $("#is_GPS").val(jsonval.rows[i].is_GPS);
    }

    if (jsonval.rows[i].is_regional != "0" && typeof (jsonval.rows[i].is_regional) != "undefined") {
        $("#is_regional").val(jsonval.rows[i].is_regional);
    }
    if (jsonval.rows[i].is_push != "0" && typeof (jsonval.rows[i].is_push) != "undefined") {
        $("#is_push").val(jsonval.rows[i].is_push);
    }
    $("#push_url").val(jsonval.rows[i].push_url);
    $("#push_account").val(jsonval.rows[i].push_account);
    $("#push_password").val(jsonval.rows[i].push_password);

    $("#explain").val(jsonval.rows[i].remarks);


    $("#static").val(jsonval.rows[i].enter_state);
    if (typeof (jsonval.rows[i].status) == "undefined") {
        $("#static").val("1");
    } else {
        $("#static").val(jsonval.rows[i].status);
    }

    //选中的公司id不等于登录的并且是单位
    if (sessionStorage.getItem("coid") != jsonval.rows[i].co_id && sessionStorage.getItem("isgroup") != "1") {
        $("#is_group").removeAttr("disabled");
    } else {
        $("#is_group").attr("disabled", true);
        

    }

    // domain.jsonthis.userinfo=[json.rows[i].user_name];

};


Date.prototype.Format = function (fmt) {
    //author:wangweizhen
    var o = {
        "M+": this.getMonth() + 1,                 //月份   
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时   
        "m+": this.getMinutes(),                 //分   
        "s+": this.getSeconds(),                 //秒   
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
        "S": this.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

